package me.j360.springboot.simple.bean.search.rule;

import org.hibernate.criterion.MatchMode;
import org.hibernate.type.Type;

import java.util.Collection;

/**
 * 说明：
 * Bean类 - 查询条件 - 快速创建帮助类
 *
 * ============================================================================
 * 版权所有 2015 qiushihua。
 *
 * @author qiushihua
 * @version 0.1 2015-07-22
 * ============================================================================
 */
public class RuleHelper {

    /**
     * and 关系
     */
    public static Rule and(Rule... rules) {
        return RuleRelation.and(rules);
    }

    /**
     * or 关系
     */
    public static Rule or(Rule... rules) {
        return RuleRelation.or(rules);
    }

    /**
     * 为空
     */
    public static Rule isEmpty(String field) {
        return RuleNull.isEmpty(field);
    }

    /**
     * 不为空
     */
    public static Rule isNotEmpty(String field) {
        return RuleNull.isNotEmpty(field);
    }

    /**
     * 为空
     */
    public static Rule isNull(String field) {
        return RuleNull.isNull(field);
    }

    /**
     * 不为空
     */
    public static Rule isNotNull(String field) {
        return RuleNull.isNotNull(field);
    }

    /**
     * 等于
     */
    public static Rule eq(String field, Object data) {
        return RuleSimple.eq(field, data);
    }

    /**
     * 大于
     */
    public static Rule gt(String field, Object data) {
        return RuleSimple.gt(field, data);
    }

    /**
     * 大于等于
     */
    public static Rule ge(String field, Object data) {
        return RuleSimple.ge(field, data);
    }

    /**
     * 小于
     */
    public static Rule lt(String field, Object data) {
        return RuleSimple.lt(field, data);
    }

    /**
     * 大于等于
     */
    public static Rule le(String field, Object data) {
        return RuleSimple.le(field, data);
    }

    /**
     * 之内
     */
    public static Rule in(String field, Object[] data) {
        return RuleSimple.in(field, data);
    }

    /**
     * 之内
     */
    public static Rule in(String field, Collection data) {
        return RuleSimple.in(field, data);
    }

    /**
     * 模糊查询
     */
    public static Rule like(String field, Object data) {
        if (data instanceof String) data = "%" + data + "%";
        return RuleLike.like(field, data);
    }

    /**
     * 模糊查询
     */
    public static Rule like(String field, String data, MatchMode matchMode) {
        return RuleLike.like(field, data, matchMode);
    }

    /**
     * 模糊查询（忽略大小写）
     */
    public static Rule ilike(String field, Object data) {
        if (data instanceof String) data = "%" + data + "%";
        return RuleLike.ilike(field, data);
    }

    /**
     * 模糊查询（忽略大小写）
     */
    public static Rule ilike(String field, String data, MatchMode matchMode) {
        return RuleLike.ilike(field, data, matchMode);
    }

    /**
     * sql 条件（当前表 别名 this_）
     */
    public static Rule sql(String sql) {
        return RuleSql.sql(sql);
    }

    /**
     * sql 条件（当前表 别名 this_）
     */
    public static Rule sql(String sql, Object[] values, Type[] types) {
        return RuleSql.sql(sql, values, types);
    }


}
